//
//  AppDelegate.m
//  PropertyManager
//
//  Created by TNG on 2018/7/3.
//  Copyright © 2018年 Tng. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate () <QQApiInterfaceDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    
//    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"token"];
//    [[NSUserDefaults standardUserDefaults] setValue:@"2" forKey:@"usertype"];

    WeakSelf;
//    if (SFMToken == nil) {
        LoginViewController * log = [[LoginViewController alloc] init];
        log.DidLoginEventBlock = ^{
            __strong typeof(weakSelf) strongSelf = weakSelf;
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                TabBarViewController * tab = [[TabBarViewController alloc] init];
                //创建动画
                CATransition *animation = [CATransition animation];
                //设置动画类型为立方体动画
                animation.type = @"rippleEffect";
                //设置动画时长
                animation.duration =1.0f;
                //设置运动的方向
                animation.subtype =kCATransitionFromRight;
                //控制器间跳转动画
                [[UIApplication sharedApplication].keyWindow.layer addAnimation:animation forKey:nil];
                [strongSelf.window.rootViewController presentViewController:tab animated:NO completion:nil];
            });
        };
        self.window.rootViewController = log;
//    }
//    else
//    {
//        self.window.rootViewController = [[TabBarViewController alloc] init];
//    }
    [self.window makeKeyAndVisible];
    
    // 设置导航栏默认的背景颜色
//    [WRNavigationBar wr_setDefaultNavBarBarTintColor:SFMNavBarColor];
    // 设置导航栏所有按钮的默认颜色
    [WRNavigationBar wr_setDefaultNavBarTintColor:SFM51];
    // 设置导航栏标题默认颜色
    [WRNavigationBar wr_setDefaultNavBarTitleColor:SFM51];
    // 统一设置状态栏样式
//    [WRNavigationBar wr_setDefaultStatusBarStyle:UIStatusBarStyleLightContent];

    //启用
    [IQKeyboardManager sharedManager].enable = YES;
    //可以显示placeHolder
    [IQKeyboardManager sharedManager].shouldShowToolbarPlaceholder=NO;
    //外部点击关闭键盘
    [IQKeyboardManager sharedManager].shouldResignOnTouchOutside=YES;
    [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
    
    [[UIView appearance] setExclusiveTouch:YES];

    [WXApi registerApp:@"wx11a74c7abdcc0d79" enableMTA:YES];
    
    return YES;
}

-(BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
    if ([TencentOAuth HandleOpenURL:url] == YES) {
        return [TencentOAuth HandleOpenURL:url];
    }else if ([url.host isEqualToString:@"safepay"])
    {
        //跳转支付宝钱包进行支付，处理支付结果
        [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
            NSString * str =resultDic[@"resultStatus"];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"AliPayDidBack" object:@{@"resultStatus":str}];
        }];
    }else
    {
        return [WXApi handleOpenURL:url delegate:[WeiChatManager shareManager]];
    }
    return YES;
}

- (void)tencentDidLogout
{
    
}

/**
 处理来至QQ的请求
 */
- (void)onReq:(QQBaseReq *)req{
    
}

/**
 处理来至QQ的响应
 */
- (void)onResp:(QQBaseResp *)resp
{
    
}

/**
 处理QQ在线状态的回调
 */
- (void)isOnlineResponse:(NSDictionary *)response
{
    
}

-(void)loadUI
{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"token"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"gbuserid"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"headimgurl"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"loginname"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"usertype"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"Id"];

    LoginViewController * load = [[LoginViewController alloc] init];
    load.DidLoginEventBlock = ^{
        
    };
    [self.window.rootViewController presentViewController:load animated:YES completion:nil];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
